package leetcode_动态规划._07背包问题.完全背包;

/**
 * @author yzh
 * @data 2021/3/19 21:15
 * 零钱兑换 II
 */
public class _518 {
    public static void main(String[] args) {
        System.out.println(new _518().change_huisu(5, new int[]{1, 2, 5}));
    }

    public int change(int amount, int[] coins) {
        int[] dp = new int[amount + 1];
        dp[0] = 1;
        for (int coin : coins) {
            for (int j = coin; j <= amount; j++) {
                dp[j] += dp[j - coin];
            }
        }
        return dp[amount];
    }

    public int change_huisu(int amount, int[] coins) {
        return dfs(0, amount, coins);
    }

    public int dfs(int begin, int amount, int[] coins) {
        if (amount == 0) {
            return 1;
        }
        int res = 0;
        for (int i = begin; i < coins.length; i++) {
            if (amount < coins[i]) continue;
            res += dfs(i, amount - coins[i], coins);
        }
        return res;
    }
}
